﻿using System.Threading.Tasks;
using JetBrains.Annotations;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Domain.Services;

namespace CommonManagement
{
    /// <summary>
    /// 余额变动记录管理类
    /// </summary>
    public class BalanceManager : DomainService
    {
        private readonly IRepository<Balance, int> _balanceRepository;

        public BalanceManager(
            IRepository<Balance, int> balanceRepository)
        {
            _balanceRepository = balanceRepository;
        }

        public async Task<Balance> CreateAsync(
            int userId,
            string appType,
            [NotNull] string changeType,
            [NotNull] string @event,
            decimal changeAmount)
        {
            return await _balanceRepository.InsertAsync(
                new Balance(
                    userId,
                    appType,
                    changeType,
                    @event,
                    changeAmount
                )
            );
        }
    }
}